import axios from 'axios'


export default {
  namespaced: true,
  state: {
    actors: {},
    moviePhotos: {},
    comments: {},
    movieMessage: {},
  },
  mutations: {
    getActors(state, actors) {//演员
      state.actors = actors
    },
    getMoviePhoto(state, moviePhotos) { //剧照
      state.moviePhotos = moviePhotos
    },
    getComments(state, comments) { //评论
      state.comments = comments
    },
    getMovieMessage(state, message) { //电影信息
      state.movieMessage = message
    }

  },
  actions: {
    async getActors({commit}, id) {
      await axios({
        url: `/mmdb/v7/movie/${id}/celebrities.json`
      }).then(res => {
        commit('getActors', res.data.data)
      })
    },
    async getMoviePhoto({commit}, id) {
      await axios({
        url: `/mmdb/movie/photos/${id}/list.json`
      }).then(res => {
        commit('getMoviePhoto', res.data.data)
      })
    },
    async getComments({commit}, {id, limit, currentPage}) {
      await axios({
        url: `/mmdb/comments/movie/v2/${id}.json?limit=${limit}&offset=${limit * currentPage}`
      }).then(res => {
        commit('getComments', res.data)
      })
    },
    async getMovieMessage({commit}, {id, ci}) {
      await axios({
        url: `/mmdb/movie/v5/${id}.json?ci=${ci}`
      }).then(res => {
        commit('getMovieMessage', res.data.data)
      })
    }

  }
}